﻿@model ZDSoft.QLMS.Entity.Question
@using ZDSoft.QLMS.Entity
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Create</title>
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
    <link href="../../Scripts/PageCreater/Css/Style.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/zTree/js/jquery.ztree.core-3.5.js" type="text/javascript"></script>
    <script src="../../Scripts/zTree/js/jquery.ztree.exedit-3.5.js" type="text/javascript"></script>
    <script src="../../Scripts/zTree/js/jquery.ztree.excheck-3.5.js" type="text/javascript"></script>
    <link href="../../Scripts/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        var i = 0;
        var ID = 0;
        function SetValue(id) {
            ID = id;
        }
        function addScroe(obj) {
            i++;
            ID = ID + i - 1;
            var xx = $(obj);
            IDs = String.fromCharCode(ID);
            xx.before("<table><tr id=" + i + "><td><input type='text' style='width: 30px;' value=" + IDs + " id='" + "option-" + ID + "' /><span>描述:</span><input type='text' style='width: 200px;' id='" + "dis-" + ID + "' /><input id='" + i + "' style='border:0;width:50px;' value='-' type='button'   onclick='delScroe(this)' > </input></td></tr> </table>");
        }
        function delScroe(Modles) {
            var id = $(Modles).attr("id");
            $("tr").remove("#" + id);
            i--;
        }
        $(function () {
            $("#Type").change(function () {
                var Text = $("#Type").val();
                if (Text != "单选题" && Text != "多选题") {
                    document.getElementById("options").style.display = 'none';
                }
                else {
                    document.getElementById("options").style.display = '';
                }
            })

        })
        function SubmitPage() {
            var pid;
            var name;
            var Text = $("#Type").val();
            if (Text != "单选题" && Text != "多选题") {
                $.ajax({
                    type: "Post",
                    url: "/Question/QuestioneCreate",
                    data: { Type: $("#Type").val(), Degree: $("#Degree").val(), Title: $("#Title").val(), Answers: $("#Answers").val(),KnowledgePointName:$("#selectName").val() },
                    success: function () {
                        $.post("/Question/GetID", { TypeName: Text }, function (data) { pid = data });
                        $.post("/Question/Text", function (data) { name=data });
                    }
                });
            }
            else {
                var options = "";
                if (ID == 0) {
                    for (var k = 65; k <= 68; k++) {
                        options += $("#option-" + k).val() + "|" + $("#dis-" + k).val() + ",";
                    }
                }
                else {
                    for (var k = 65; k <= ID; k++) {
                        options += $("#option-" + k).val() + "|" + $("#dis-" + k).val() + ",";
                    }
                }
                $.ajax({
                    type: "Post",
                    url: "/Question/ChoiceQuestioneCreate",
                    data: { Type: $("#Type").val(), Degree: $("#Degree").val(), Title: $("#Title").val(), Answers: options, CorrectAnswer: $("#Answers").val(),KnowledgePointName:$("#selectName").val()},
                    success: function () {
                        $.post("/Question/GetID", { TypeName: Text }, function (data) { pid = data });
                        $.post("/Question/Text", function (data) { name = data });
                    }
                });
            }
            alert("添加成功!");
            window.parent.AddNode(pid,name);
            window.location = "/Question/NULL";
        }
        //Ztree
        var setting = {
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                beforeClick: zTreeOnClick
            }
        };

        function zTreeOnClick(treeContainer, treeNode,treeId) {
        if(treeNode.id=="")
        {
          $("#selectId").val();
        }
        else
        {
          $("#selectId").val(treeNode.id);
          }
            $("#selectName").val(treeNode.name);
        };

        var zNodes = [
		 @Html.Raw(@TempData["Ztree"].ToString())
			
		];

        var code;
        function setCheck() {
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        }

        $(document).ready(function () {
            setCheck();
        });

    </script>
</head>
<body>
    @{
        var i = 65;
    }
    <div style="background-color: Skyblue; color: Red; width: 100%; height: 20px;">
        <span style="font-size: small;">小提示：添加多项选择题时，多个答案选项用"，"隔开！</span>
    </div>
    <div class="zTreeDemoBackground left" style="float: right; width: auto; height: auto;
        font-size: 13px;">
        <div style="font-weight: bold; font-size: 12px; padding-top: 5px; padding-bottom: 5px;">
            选择知识点</div>
        <ul id="treeDemo" class="ztree">
        </ul>
        本题知识点
        <input type="text" id="selectName" style="font-size: 13px;" />
    </div>
    <br />
    <div>
        <div class="content_top">
            <div class="contrnt_top_center">
                选择题型：<select id="Type">
                    @{
                        foreach (ZDSoft.QLMS.Entity.Type type in (IList<ZDSoft.QLMS.Entity.Type>)TempData["Types"])
                        {
                        <option value= "@type.Name">@type.Name</option>;
                        }
                    }
                </select></div>
            <br />
            <div>
                难易程度：<select id="Degree">
                    <option value="1">简单</option>
                    <option value="2">一般</option>
                    <option value="3">困难</option>
                    <option value="4">非常困难</option>
                </select>
            </div>
            <div class="contrnt_top_right">
            </div>
        </div>
        <div class="content_center">
            <div>
                <div style="margin-top: 10px; margin-left: 10px;">
                    <span>题目：</span><input id="Title" type="text" style="width: 500px; height: 50px;" /><br />
                    <br />
                    <div>
                    </div>
                </div>
                <div style="margin-left: 10px;">
                    <div id="options">
                        <table>
                            <tr>
                                <td>
                                    <span>选项：</span><br />
                                    <input id="option-@i" type="text" value=@(Convert.ToChar(i)) style="width: 30px;" /><span>描述:</span><input
                                         id="dis-@i" type="text" style="width: 200px;" />
                                    @{i++;}
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input id="option-@i" type="text" value=@(Convert.ToChar(i)) style="width: 30px;" /><span>描述:</span><input
                                       id="dis-@i" type="text" style="width: 200px;" />
                                    @{i++;}
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input id="option-@i" type="text" value=@(Convert.ToChar(i)) style="width: 30px;" /><span>描述:</span><input
                                        id="dis-@i" type="text" style="width: 200px;" />
                                    @{i++;}
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input id="option-@i" type="text" value=@(Convert.ToChar(i)) style="width: 30px;" /><span>描述:</span><input
                                        id="dis-@i" type="text" style="width: 200px;" />
                                    @{i++;}
                                    <input type="button" style="border: 0; width: 50px;" onclick="addScroe(LOL)" value="+"  onmousedown="SetValue(@i)" />
                                </td>
                            </tr>
                        </table>
                        <div id="LOL">
                        </div>
                    </div>
                    <div id="answers">
                        <br />
                        <br />
                        <span>答案：</span><input id="Answers" type="text" style="width: 500px; height: 50px;" />
                    </div>
                </div>
            </div>
        </div>
        <br />
        <div class="down">
            <input type="button" value="保存" class="btn3" style="margin: 20px;" onclick="SubmitPage()" /></div>
    </div>
</body>
</html>
